/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package InterviewerManagerment.jdbc;

import InterviewerManagerment.entities.Interview;
import connection.Configuration;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Tngoc
 */
public class Interviews {
    private ArrayList<Interview> interviews;
    private Connection conn;
    private int id;
    
    public Interviews(int id){
        this.id=id;
        this.interviews = new ArrayList<>();
        getInfomation();
    }
    
    private void getInfomation(){
        try {
            conn= new Configuration().getConnect();
            CallableStatement cs = conn.prepareCall("{call showMyInterview ("+id+")}");
            ResultSet rs = cs.executeQuery();
            while(rs.next()){
                Interview i = new Interview();
                i.setID(rs.getInt("ID"));
                i.setAmount(rs.getInt("amount"));
                i.setChangeRequest(rs.getBoolean("changeRequest"));
                i.setDate(rs.getDate("date"));
                i.setField(rs.getString("fieldName"));
                i.setResult(rs.getString("result"));
                i.setSalary(rs.getFloat("salary"));
                i.setSeekerID(rs.getInt("seekerID"));
                i.setSeekerName(rs.getString("seekerName"));
                i.setVacancyID(rs.getInt("vacancyID"));
                interviews.add(i);
            }
        } catch (SQLException ex) {
            Logger.getLogger(Interviews.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public ArrayList<Interview> getInterviews() {
        return interviews;
    }

    public void setInterviews(ArrayList<Interview> interviews) {
        this.interviews = interviews;
    }
    
    public void refresh(){
        interviews.clear();
        getInfomation();
    }
    
}
